<template>
  <div class="app-container">
    <el-form :model="query" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商户名称：" prop="merchantName" label-width="100px">
        <el-input
          v-model="query.merchantName"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="门店地址：" prop="merchantAddress" label-width="100px">
        <el-input
          v-model="query.merchantAddress"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" class="button">筛选</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['carService:information:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['carService:information:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <!--表格区域-->
    <el-table v-loading="loading" :data="informationList" @selection-change="handleSelectionChange"  :border="true">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="标题" align="center" prop="riTitle" width="130px"/>
      <el-table-column label="发布内容" align="center" prop="riContent"  width="250px" show-overflow-tooltip="true">
      </el-table-column>
      <el-table-column label="发布人" align="center" prop="riPerson" width="130px"/>
      <el-table-column label="审核状态" align="center" prop="riReviewStatus" width="130px">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.riReviewStatus === 0" type="danger">审核不通过</el-tag>
          <el-tag v-else>审核通过</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="发布时间" align="center" prop="riTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.riTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="primary"
                     icon="el-icon-search"
                     class="button"
                     @click="handleQuery1(scope.row)"
                     v-hasPermi="['carService:information:query']">详情</el-button>
          <el-button
            v-if="scope.row.riReviewStatus === 2 "
            type="primary"
            icon="el-icon-search"
            class="button"
            @click="handleChange(scope.row)">审核</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!--  查看信息发布详情对话框-->
    <el-dialog :title="title" :visible.sync="open1" width="800px" append-to-body >
      <el-descriptions  :column="1" size="medium" border>
        <el-descriptions-item >
          <template slot="label">
            <div class="margin-top">
              <i class="el-icon-user"></i>标题</div>
          </template>
          <div class="margin-top">{{ReleaseInformation.riTitle}}</div>
        </el-descriptions-item>
        <el-descriptions-item >
          <template slot="label">
            <div class="margin-top"><i class="el-icon-mobile-phone"></i>发布人</div>
          </template>
          <div class="margin-top">{{ReleaseInformation.riPerson}}</div>
        </el-descriptions-item>
        <el-descriptions-item >
          <template slot="label">
            <div class="margin-top"><i class="el-icon-location-outline"></i>发布时间</div>
          </template>
          <div class="margin-top">{{ReleaseInformation.riTime}}</div>
        </el-descriptions-item>
        <el-descriptions-item class="margin-top">
          <template slot="label">
            <div class="margin-top"><i class="el-icon-tickets"></i>内容</div>
          </template>
          <div class="margin-top">{{ReleaseInformation.riContent}}</div>
        </el-descriptions-item>
        <el-descriptions-item class="margin-top">
          <template slot="label">
            <div class="margin-top"><i class="el-icon-office-building"></i>图片</div>
          </template>
          <el-image
            v-for="item in imageArr"
            style="width: 100px; height: 100px; margin-right: 20px"
            :src="item"
            fit="fill"></el-image>
        </el-descriptions-item>
      </el-descriptions>

      <el-descriptions  :column="4 " size="medium" border direction="vertical">
        <el-descriptions-item >
          <template slot="label">
            <div class="margin-top">
              <i class="el-icon-user"></i>审核时间</div>
          </template>
          <div class="margin-top">{{checkInformation.ciTime}}</div>
        </el-descriptions-item>
        <el-descriptions-item >
          <template slot="label">
            <div class="margin-top"><i class="el-icon-mobile-phone"></i>审核结果</div>
          </template>
          <div class="margin-top" v-if="checkInformation.ciResult === 1">审核通过</div>
          <div class="margin-top" v-else>审核不通过</div>
        </el-descriptions-item>
        <el-descriptions-item >
          <template slot="label">
            <div class="margin-top"><i class="el-icon-location-outline"></i>审核说明</div>
          </template>
          <div class="margin-top">{{checkInformation.ciExplain}}</div>
        </el-descriptions-item>
        <el-descriptions-item class="margin-top">
          <template slot="label">
            <div class="margin-top"><i class="el-icon-tickets"></i>审核人</div>
          </template>
          <div class="margin-top">{{checkInformation.ciChecker}}</div>
        </el-descriptions-item>
      </el-descriptions>



      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">返 回</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<style>
.button{
  background-color: #6A8BF2;
  border: #6A8BF2 1px solid;
}
.margin-top{
  text-align: center;
}
.content{
  width: 30px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>

<script>
import {
  getInformation,
  delInformation,
  addInformation,
  updateInformation,
  queryReleaseByLike, queryReleaseUnCheck
} from "@/api/carService/information";
import {parseTime} from "../../../utils/ruoyi";
import {getCheck, getCheckByRiId} from "@/api/carService/check";

export default {
  name: "Information",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 信息发布表格数据
      informationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 店铺ID时间范围
      daterangeRiTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        riTitle: null,
        riContent: null,
        riPerson: null,
        riStatus: null,
        riTime: null,
        riReviewStatus: null,
        riShopId: null,
      },
      // 表单参数
      form: {
        riContent: '',
      },
      // 表单校验
      rules: {
        riTitle: [
          { required: true, message: "标题不能为空", trigger: "blur" }
        ],
        riPerson: [
          { required: true, message: "发布人不能为空", trigger: "blur" }
        ],
        riTime: [
          { required: true, message: "发布时间不能为空", trigger: "blur" }
        ],
        riShopId: [
          { required: true, message: "店铺ID不能为空", trigger: "blur" }
        ]
      },





      //查看详情的弹出层
      open1: false,
      ReleaseInformation:{
        riTitle: null,
        riTime: null,
        riContent: null,
        riPerson: null,
        riImage: null
      },
      //   图片数组
      imageArr:[],
      //模糊查询的参数
      query:{
        merchantName: null,
        merchantAddress: null
      },
      //审核信息表
      checkInformation: {
        ciTime: null,
        ciResult: null,
        ciExplain: null,
        ciChecker: null

      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    parseTime,
    /** 查询信息发布列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeRiTime && '' != this.daterangeRiTime) {
        this.queryParams.params["beginRiTime"] = this.daterangeRiTime[0];
        this.queryParams.params["endRiTime"] = this.daterangeRiTime[1];
      }
      queryReleaseUnCheck().then(response => {
        this.informationList = response.rows;
        this.total = response.total;
        this.loading = false;
      })

    },
    // 取消按钮
    cancel() {
      this.open1 = false;
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        riId: null,
        riTitle: null,
        riContent: null,
        riPerson: null,
        riStatus: null,
        riTime: null,
        riReviewStatus: null,
        riShopId: null
      };
      this.query = {
        merchantName: null,
        merchantAddress: null
      };
      this.checkInformation = {
        ciTime: null,
        ciResult: null,
        ciExplain: null,
        ciChecker: null
      };
      this.resetForm("form");
      this.resetForm("query");
      this.resetForm("check")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      queryReleaseByLike(this.query).then(response => {
        this.informationList = response;
      }).catch(()=>{})
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeRiTime = [];
      this.resetForm("query");
      this.query = {
        merchantName: null,
        merchantAddress: null
      };
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.riId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加信息发布";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const riId = row.riId || this.ids
      getInformation(riId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改信息发布";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["queryForm"].validate(valid => {
        if (valid) {
          if (this.form.riId != null) {
            updateInformation(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            // 获取当前时间
            let now = new Date();
            let year = now.getFullYear();
            let month = now.getMonth() + 1;
            let day = now.getDate();
            //当前登录用户
            let userName = this.$store.state.user.name;
            // 当前时间
            this.form.riTime = year + "-" + month + "-" + day;
            // 当前用户
            this.form.riPerson = userName;
            addInformation(this.form).then(response => {
              console.log(this.form)
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const riIds = row.riId || this.ids;
      this.$modal.confirm('是否确认删除信息发布编号为"' + riIds + '"的数据项？').then(function() {
        return delInformation(riIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('carService/information/export', {
        ...this.queryParams
      }, `information_${new Date().getTime()}.xlsx`)
    },


    /** 详情按钮操作 */
    handleQuery1(row) {
      this.open1 = true;
      this.ReleaseInformation = row;
      var str = this.ReleaseInformation.riImage;
      this.imageArr = str.split(',')


      var riId = row.riId
      console.log(riId)
      //根据信息发布id查询
      getCheckByRiId(riId).then( response =>{
        console.log(response)
        this.checkInformation = response.data
      })

    },
    //   上下架按钮
    handleChange(row){
      this.form = row
      var num = row.riStatus
      num = (num +1 )%2
      this.form.riStatus = num
      updateInformation(this.form).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.open = false;
        this.getList();
      });
      // this.submitForm();
      // console.log(this.form)
      // console.log(row)
    },
  },
};
</script>

